//
//  SYOAuthProgressView.swift
//  SYWeibo
//
//  Created by Eric on 16/7/21.
//  Copyright © 2016年 Eric. All rights reserved.
//

import UIKit

class SYOAuthProgressView: UIProgressView {
    
    //定义一个定时器
    var timer: NSTimer?
    //设置动画的一个默认的状态是开启动画的
    var isAnim: Bool = true
    
    override init(frame: CGRect) {
        super.init(frame: CGRect(x: 0, y: 64, width: SCREENW, height: 2))
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - 设置视图
    private func setupUI(){
        //进度条的颜色
        self.tintColor = UIColor.greenColor()
        
    }
    
    //MARK: - 给外界访问
    //开始动画
    func startAnim(){
        self.progress = 0
        self.hidden = false
        timer = NSTimer.scheduledTimerWithTimeInterval(1/60, target: self, selector: "valueChange", userInfo: nil, repeats: true)
    }
    //结束动画
    func endAnim(){
        isAnim = false
    }
    
    //删除当前的控件
    func removeVie(){
        
        removeFromSuperview()
        
    }
    
    func valueChange(){
        if isAnim {
            self.progress += 0.05
            
            if self.progress >= 0.8{
                
                self.progress = 0.95
            }
        }else{
            
            self.progress = 1
            
            
        }
        
    }
    //释放这个    不是放回循环引用
    deinit{
        timer?.invalidate()
    }
}

